import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { ConfigService } from '../../services/admin/config.service';

/**
 * ConfigController
 * 对应 PHP: Config Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('sys')
@Controller('adminapi/sys')
export class ConfigController {
  constructor(private readonly configService: ConfigService) {}

  /**
   * 配置管理
   * 路由: GET config/website
   * PHP路由: Route::get('config/website', 'sys.Config/getWebsite')
   */
  @Get('config/website')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async getWebsite(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getWebsite

      return await this.configService.getWebSite();
    } catch (error) {
      throw new BusinessException('getWebsite操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: PUT config/website
   * PHP路由: Route::put('config/website', 'sys.Config/setWebsite')
   */
  @Put('config/website')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async setWebsite(@Body() data: SetWebsiteDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setWebsite

      return await this.configService.setWebSite(data);
    } catch (error) {
      throw new BusinessException('setWebsite操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: GET config/copyright
   * PHP路由: Route::get('config/copyright', 'sys.Config/getCopyright')
   */
  @Get('config/copyright')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async getCopyright(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getCopyright

      return await this.configService.getCopyright();
    } catch (error) {
      throw new BusinessException('getCopyright操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: PUT config/copyright
   * PHP路由: Route::put('config/copyright', 'sys.Config/setCopyright')
   */
  @Put('config/copyright')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async setCopyright(@Body() data: SetCopyrightDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setCopyright

      return await this.configService.setCopyright(data);
    } catch (error) {
      throw new BusinessException('setCopyright操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: GET scene_domain
   * PHP路由: Route::get('scene_domain', 'sys.Config/getSceneDomain')
   */
  @Get('scene_domain')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async getSceneDomain(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getSceneDomain

      return await this.configService.getSceneDomain();
    } catch (error) {
      throw new BusinessException('getSceneDomain操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: GET config/service
   * PHP路由: Route::get('config/service', 'sys.Config/getServiceInfo')
   */
  @Get('config/service')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async getServiceInfo(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getServiceInfo

      return await this.configService.getService();
    } catch (error) {
      throw new BusinessException('getServiceInfo操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: PUT config/map
   * PHP路由: Route::put('config/map', 'sys.Config/setMap')
   */
  @Put('config/map')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async setMap(@Body() data: SetMapDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setMap

      return await this.configService.setMap(data);
    } catch (error) {
      throw new BusinessException('setMap操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: GET config/map
   * PHP路由: Route::get('config/map', 'sys.Config/getMap')
   */
  @Get('config/map')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async getMap(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getMap

      return await this.configService.getMap();
    } catch (error) {
      throw new BusinessException('getMap操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: GET config/developer_token
   * PHP路由: Route::get('config/developer_token', 'sys.Config/getDeveloperToken')
   */
  @Get('config/developer_token')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async getDeveloperToken(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getDeveloperToken

      return await this.configService.getDeveloperToken();
    } catch (error) {
      throw new BusinessException('getDeveloperToken操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: PUT config/developer_token
   * PHP路由: Route::put('config/developer_token', 'sys.Config/setDeveloperToken')
   */
  @Put('config/developer_token')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async setDeveloperToken(
    @Body() data: SetDeveloperTokenDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setDeveloperToken

      return await this.configService.setDeveloperToken(data);
    } catch (error) {
      throw new BusinessException('setDeveloperToken操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: PUT config/layout
   * PHP路由: Route::put('config/layout', 'sys.Config/setLayout')
   */
  @Put('config/layout')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async setLayout(@Body() data: SetLayoutDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setLayout

      return await this.configService.setLayout(data);
    } catch (error) {
      throw new BusinessException('setLayout操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: GET config/layout
   * PHP路由: Route::get('config/layout', 'sys.Config/getLayout')
   */
  @Get('config/layout')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async getLayout(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getLayout

      return await this.configService.getLayout();
    } catch (error) {
      throw new BusinessException('getLayout操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: PUT config/themecolor
   * PHP路由: Route::put('config/themecolor', 'sys.Config/setThemeColor')
   */
  @Put('config/themecolor')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async setThemeColor(@Body() data: SetThemeColorDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setThemeColor

      return await this.configService.setThemeColor(data);
    } catch (error) {
      throw new BusinessException('setThemeColor操作失败', error);
    }
  }

  /**
   * 配置管理
   * 路由: GET config/themecolor
   * PHP路由: Route::get('config/themecolor', 'sys.Config/getThemeColor')
   */
  @Get('config/themecolor')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '配置管理' })
  async getThemeColor(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getThemeColor

      return await this.configService.getThemeColor();
    } catch (error) {
      throw new BusinessException('getThemeColor操作失败', error);
    }
  }
}
